
func toggleIfClosed() {
    if isOnClosedSwitch {
        toggleSwitch()
    }
}

for i in 1...4 {
    moveForward()
    toggleIfClosed()
}
